package com.hmall.item.listenel;

import com.hmall.item.domain.dto.OrderDetailDTO;
import com.hmall.item.service.impl.ItemServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
@RequiredArgsConstructor
public class ItemClearListenel {
    private final ItemServiceImpl itemService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.clear.queue",durable = "true"),
            exchange = @Exchange(value = "item.clear.direct",type = "direct"),
            key = "item.clear"
    ))
    public void clearItemListenel(List<OrderDetailDTO> items){
        System.out.println("item监听到扣减库存的消息，开始运行。。。");
        itemService.deductStock(items);
    }

}
